<!DOCTYPE html>
<html lang="cs">
<head>
        <title>untitled</title>
        <meta http-equiv="content-type" content="text/html;charset=utf-8" />
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> 
<style type="text/css">
body {font-family: Helvetica, Arial, sans-serif;width:500px}
table tr td {border:1px solid #CCC; font-size:0.8em}
</style>
<script type="text/javascript">
var pocet = 0;
function getSubstitution(date, myClass) {
        var month, day;
        
        month = date.getMonth() + 1;
        day = date.getDate();
        
        if(day < 10)
          day = "0" + day;
          
        if(month < 10)
          month = "0" + month;
        
        var textDate = date.getFullYear() + "" + month + ""
                  + day;
        
        $.ajax({
                url: "http://sps-tabor.cz/rozvrh-supl/supl/supl_" + textDate + ".htm",
                async: true,
                type: "GET",
                success: function (result) {
                        var i = 0;
                        
                        $("td.C11", result).each(function() {
                                if ($(this).text() == myClass) {
                                  pocet++;
                                        if (i == 0) {
                                                $("#content").append('<h2>' + date.getDate() +
                                                        "." + (date.getMonth() + 1) + '</h2><table id="' +
                                                        textDate + '"></table>');
                                        }
                                        $("#" + textDate).append("<tr>" + $(this).parent().html() +
                                                "</tr>");
                                        i++;
                                }
                        });
                       /* chrome.browserAction.setBadgeText({text:String(pocet)});
                        chrome.browserAction.setBadgeBackgroundColor({color:[0, 255, 0, 150]});*/
                },
                error: function (xhr, statusMessage, exception) {
                        console.log(statusMessage);
                }
        });
}

$(document).ready(function () {
        var now = new Date();
        var days = localStorage.getItem("days");
        var date;
        var i = 0;
        
        for (i = 0; i <= days; i++) {
                date = new Date(now.getTime() + i * 24 * 60 * 60 * 1000);
                getSubstitution(date, localStorage.getItem("class"));
        }
        
});
</script>
</head>
<body>
        <div id="content"></div>
</body>
</html>
